package com.joinlabs.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.joinlabs.entity.User;
import com.joinlabs.service.IUserService;
import com.joinlabs.service.IUserServiceZ;

@Controller
@RequestMapping("/login")
@SessionAttributes(names= {"user"})
public class LoginCheck {
	@Resource
	private IUserServiceZ userservice;
	@RequestMapping("/check")                   
	      //判断用户是否登录成功与是否被拉入黑名单，若成功将user塞入域对象中
	public ModelAndView check(User user,ModelMap map) {
		User us = userservice.findUserAccount(user.getUserAccount());
		if(us == null) {
			return new ModelAndView("redirect:/login/index");
		} else if(us.getUserBlacklist()==1) {
			return new ModelAndView("redirect:/login/hmd");
			
		} else if(us.getUserPassword().equals(user.getUserPassword())){
			map.addAttribute("user", us);
			return new ModelAndView("redirect:/friend/index");
		}else {
			return new ModelAndView("redirect:/login/index");
		}		
	}
	
	

	
	@RequestMapping("/register")
	public ModelAndView register() {
		return new ModelAndView("redirect:/login/index");
	}

}
